#!/bin/bash

Session=$1
session_arr=$(ls -1 ~/bin/tmux/)

function usage() {
    echo "t < ls | session-name >"
    echo ""
    echo "sessions below :  "
    echo ""
    ls -1 ~/bin/tmux/
    exit 10
}

for i in ${session_arr[@]}
do
    source ~/bin/tmux/$i
done

if [ "x$Session" == "xls" ]; then
    ls -1 ~/bin/tmux/
elif [ -f ~/bin/tmux/$Session ]; then
    tmux start-server
    tmux has-session -t $Session 2>/dev/null
    Res=$?
    if [ $Res != 0 ] ;then
        tmux_$Session
    fi
    tmux attach-session -d -t $Session
else
    usage
fi
